//////////////////////////////////////////////////////////////////////////////////
//	Copyright 2011 by Yosef Grabivker, ryuho@homenetworksoft.com
//
//   Licensed under the Apache License, Version 2.0 (the "License");
//   you may not use this file except in compliance with the License.
//   You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
//   Unless required by applicable law or agreed to in writing, software
//   distributed under the License is distributed on an "AS IS" BASIS,
//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//   See the License for the specific language governing permissions and
//   limitations under the License.
//////////////////////////////////////////////////////////////////////////////////

#include <wx/wx.h>
#include <wx/gbsizer.h>
#include <wx/combobox.h>
#include "reactionchooser.h"

enum cSliderID
{
	cComboIDWarning=11000,
	cComboIDAlarm
};

BEGIN_EVENT_TABLE(CReactionChooser, wxPanel)
	EVT_TEXT(cComboIDWarning, 	CReactionChooser::OnWarningChanged)
	EVT_TEXT(cComboIDAlarm, 	CReactionChooser::OnAlarmChanged)
END_EVENT_TABLE()


CReactionChooser::CReactionChooser(wxWindow* pParent, PANELTYPE type):wxPanel(pParent, wxID_ANY)
{
	wxGridBagSizer *pGrid = new wxGridBagSizer(10, 10);
		 	
 	wxStaticText *pWarning 	= new wxStaticText(this, wxID_ANY, _("On Warning level do:"));
 	wxStaticText *pAlarm   	= new wxStaticText(this, wxID_ANY, _("On Alarm level do:"));
 	
	m_pcWarning	= new wxComboBox(this, 	cComboIDWarning, _("Nothing"), wxDefaultPosition, wxSize(100, wxDefaultSize.GetY()), 0, NULL, wxCB_DROPDOWN|wxCB_READONLY  );
	m_pcAlarm  	= new wxComboBox(this, 	cComboIDAlarm, _("Nothing"), wxDefaultPosition, wxSize(100, wxDefaultSize.GetY()), 0, NULL, wxCB_DROPDOWN|wxCB_READONLY );

	//Nothing
	m_pcWarning->Append ( _("Nothing"), (void*)cRCACTNothing);
	m_pcAlarm->Append ( _("Nothing"), (void*)cRCACTNothing);

	if ( type!=cPTCPU && type!=cPTMem )
	{
		/*
		//Grow
		m_pcWarning->Append ( _("Grow"), (void*)cRCACTGrow);
		m_pcAlarm->Append ( _("Grow"), (void*)cRCACTGrow);
		*/
			
		if ( type!=cPTNAT )
		{
			//Flush
			m_pcWarning->Append ( _("Flush"), (void*)cRCACTFlush);
			m_pcAlarm->Append ( _("Flush"), (void*)cRCACTFlush);
		}
	}

	//Reboot
	m_pcWarning->Append ( _("Reboot"), (void*)cRCACTReboot);
	m_pcAlarm->Append ( _("Reboot"), (void*)cRCACTReboot);

	m_pcWarning->SetSelection( 0 );
	m_pcAlarm->SetSelection( 0 );

	pGrid->Add(pWarning, 	wxGBPosition(0,0), wxDefaultSpan);
 	pGrid->Add(m_pcWarning, wxGBPosition(1,0), wxDefaultSpan, wxEXPAND, 10 );
	pGrid->Add(pAlarm, 		wxGBPosition(2,0), wxDefaultSpan);
 	pGrid->Add(m_pcAlarm,	wxGBPosition(3,0), wxDefaultSpan, wxEXPAND, 10 );
 	
 	SetSizer( pGrid );
}

CReactionChooser::~CReactionChooser()
{
}

RECOVERYSTRAT CReactionChooser::GetWarningStrat()
{
	return m_cWarning;
}

RECOVERYSTRAT CReactionChooser::GetAlarmStrat()
{
	return m_cAlarm;
}

void CReactionChooser::SetWarningStrat( RECOVERYSTRAT s )
{
	m_cWarning = s;
	SelectValue( m_pcWarning, s);
}

void CReactionChooser::SetAlarmStrat( RECOVERYSTRAT s )
{
	m_cAlarm = s;
	SelectValue( m_pcAlarm, s);
}

void CReactionChooser::SelectValue(wxComboBox*	pBox, RECOVERYSTRAT s )
{
	void* pData;
	
	for ( size_t i=0;i<pBox->GetCount();i++ )
	{
		pData = pBox->GetClientData( i );
		
		if ( s == (RECOVERYSTRAT)(int)pData )
		{
			pBox->SetSelection( i );
			break;
		}
	}
}

void CReactionChooser::OnWarningChanged(wxCommandEvent&)
{
	void* pData = m_pcWarning->GetClientData( m_pcWarning->GetCurrentSelection());
	m_cWarning = (RECOVERYSTRAT)(int)pData;
}

void CReactionChooser::OnAlarmChanged(wxCommandEvent&)
{
	void* pData = m_pcAlarm->GetClientData( m_pcAlarm->GetCurrentSelection() );
	m_cAlarm = (RECOVERYSTRAT)(int)pData;
}
